# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

SRC ?= .
CCFLAGS += -Wall
UNITTEST_LIBS := $(shell gmock-config --libs) $(shell gtest-config --libs)
BINS = memento_updater split_write
TEST_BINS = general_installer_unittest \
            diskimage_installer_unittest \
            recovery_installer_unittest
UTILITIES = mount_handler.o tempfile_handler.o

all: $(BINS)

tests: $(BINS) $(TEST_BINS)

run-basic-tests: tests
	# Some unit tests need to download a large payload from network so for
	# "basic tests" we only run a smaller set of tests that can be finished
	# in seconds.
	sudo ./general_installer_unittest

run-all-tests: tests
	for TEST in $(TEST_BINS); do sudo ./$$TEST; done

%_unittest: %_unittest.cc %.o general_installer.o $(UTILITIES)
	$(CXX) $(CCFLAGS) $(UNITTEST_LIBS) -o $@ $^

recovery_installer_unittest: recovery_installer_unittest.cc \
                             recovery_installer.o \
			     diskimage_installer.o \
			     general_installer.o \
			     $(UTILITIES)
	$(CXX) $(CCFLAGS) $(UNITTEST_LIBS) -o $@ $^

memento_updater: memento_updater.o general_installer.o command_handler.o \
                 diskimage_installer.o recovery_installer.o $(UTILITIES)
	$(CXX) $(CCFLAGS) -o $@ $^

split_write: split_write.cc
	$(CXX) $(CCFLAGS) -DSPLIT_WRITE_MAIN -o $@ $<

%.o: %.cc memento_common.h
	$(CXX) $(CCFLAGS) -c -o $@ $<

clean:
	rm -f *.o $(BINS) $(TEST_BINS)

.PHONY:	all tests run-basic-tests run-all-tests clean
